Skip to content

Add bounded-memory training and colocation controls#1890

Open
YJHMITWEB wants to merge 4 commits into
NovaSky-AI:mainfrom
YJHMITWEB:memory-efficiency-patches
Open

Add bounded-memory training and colocation controls#1890
YJHMITWEB wants to merge 4 commits into
NovaSky-AI:mainfrom
YJHMITWEB:memory-efficiency-patches

Conversation

@YJHMITWEB

@YJHMITWEB YJHMITWEB commented Jul 13, 2026

Copy link
Copy Markdown

Bounded-Memory Megatron Training and Colocation

Summary

This PR adds controls that bound temporary training memory and make colocated Megatron offload behavior complete.

Changes

Change Explanation
CPU-resident policy microbatches Keeps the DP-sharded policy batch on CPU and transfers one nested microbatch to CUDA immediately before its forward step.
Bounded vocabulary entropy Chunks Megatron vocabulary entropy by an explicit size or an automatically calculated memory budget, and skips fully masked chunks.

CPU-resident policy microbatches is opt-in; automatic vocabulary-entropy chunk sizing, which defaults to a 512 MiB temporary-memory budget.

Memory Validation

Variant Memory Spike Outcome
Earlier configuration 9.3 GiB OOM easily as the context/vocab size gets larger
Bounded-memory configuration 0.5 GiB All memory spikes are under control

@jinghanyao1-hub jinghanyao1-hub self-assigned this Jul 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several memory optimization features, including CPU-resident microbatches, sequence-dimension chunking for Megatron vocab entropy computation, and a colocated worker memory barrier with optional hard-eviction for inactive reference workers. The review feedback suggests mapping PyTorch device indices to physical GPU indices via CUDA_VISIBLE_DEVICES to ensure accurate NVML memory statistics, and removing a fragile .squeeze(0) call on entropy chunks to robustly support varying input dimensions.

Comment thread skyrl/backends/skyrl_train/workers/worker.py Outdated
Comment thread skyrl/backends/skyrl_train/distributed/megatron/model_utils.py Outdated
Comment thread skyrl/backends/skyrl_train/workers/worker.py Outdated
Comment thread skyrl/backends/skyrl_train/distributed/megatron/model_utils.py Outdated
@NovaSky-AI NovaSky-AI deleted a comment from gemini-code-assist Bot Jul 13, 2026
@NovaSky-AI NovaSky-AI deleted a comment from gemini-code-assist Bot Jul 13, 2026
@YJHMITWEB
YJHMITWEB force-pushed the memory-efficiency-patches branch from 9b6a19a to 8af9294 Compare July 16, 2026 18:39
@YJHMITWEB
YJHMITWEB force-pushed the memory-efficiency-patches branch from 8af9294 to 782a8c7 Compare July 17, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants